# -*- coding:utf-8 -*-

# @Time    : 2023/8/31 19:40
# @Author  : zengwenjia
# @Email   : zengwenjia@lingxi.ai
# @File    : call_llm.py
# @Software: LLM_internal

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import requests
import json


def get_access_token():
    """
    使用 API Key，Secret Key 获取access_token，替换下列示例中的应用API Key、应用Secret Key
    """

    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=X8TlvTouC1rUTiMNxaaOlgoG&client_secret=7fA2Mzo1Lc5orBoK2oKglkmRu9RSAhe5"

    payload = json.dumps("")
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json().get("access_token")


def main():
    url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token=" + get_access_token()

    payload = json.dumps({
        "messages": [
            {
                "role": "user",
                "content": """我希望你扮演一个“思维链的构建者”的角色。你的任务是将给定的信息补充其推理的步骤用于通过COT（思维链）方式训练类型那些著名的AI系统（例如ChatGPT和GPT4）的推理能力。
                信息如下：
                 问题是：(2.65-1(1/4))/((4.5-3(1/3))*0.48)．
                 答案是: 2.5
                    请你用COT的方式训练ChatGPT和GPT4的推理能力，让它们能够推理出答案是2.5的结果，具体的推理步骤是:
                   """
            }
        ],
        "stream": False,
    })
    headers = {
        'Content-Type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload, stream=True)

    print(json.loads(response.text)["result"])




if __name__ == '__main__':
    main()